﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using QuanLyKho.PhongMau;

namespace QuanLyKho.Control
{
    public partial class PhongMau_KhongDuyet : UserControl
    {
        public PhongMau_KhongDuyet()
        {
            InitializeComponent();
            Loaddata();
            SetPropertiesGrid();
        }

        public void Loaddata()
        {
            DataTable data = DataAll.SelectAll("PhongMau_KhongDuyet", "*", " WHERE TrangThai = "+Convert.ToInt32(TrangThai.PhongMau_TaoMoi));
            gridNhapKho.DataSource = data;
        }

        public void SetPropertiesGrid()
        {
            gvNhapKho.BestFitColumns();
            gvNhapKho.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            gvNhapKho.OptionsBehavior.Editable = false;
            gvNhapKho.OptionsSelection.EnableAppearanceFocusedCell = false;
            gvNhapKho.OptionsSelection.MultiSelect = true;
            gvNhapKho.OptionsView.ShowGroupPanel = false;
            //gvNhapKho.OptionsView.ColumnAutoWidth = false;
            gvNhapKho.OptionsView.ShowFooter = true;
            gvNhapKho.OptionsFind.AlwaysVisible = true;
            SetPropertiesColumns();
        }

        public void SetPropertiesColumns()
        {
            gvNhapKho.Columns["MaIDNhapKho"].Visible = false;
            gvNhapKho.Columns["MaNhapKho"].Visible = false;
        }

        private void gvNhapkho_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            
        }

        private void bntThemMoi_Click(object sender, EventArgs e)
        {
            var nhapkho = new PhongMau_KhongDuyetPopup();
            nhapkho.ShowDialog();
            Loaddata();
        }

        private void gridNhapKho_DoubleClick(object sender, EventArgs e)
        {
            if (gvNhapKho.FocusedRowHandle >=0)
            {
                PhongMau_KhongDuyetPopup.MaID = gvNhapKho.Columns["MaIDNhapKho"].View.GetRowCellDisplayText(gvNhapKho.FocusedRowHandle, "MaIDNhapKho");
                var nhapkho = new PhongMau_KhongDuyetPopup();
                nhapkho.update = true;
                nhapkho.ShowDialog();
                Loaddata();
                PhongMau_KhongDuyetPopup.MaID = "0";
            } 
        }

        private void gvNhapKho_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {

        }
    }
}
